//
//  NoticeView.swift
//  Order
//
//  Created by Lazyloading on 2020/7/10.
//  Copyright © 2020 lazyloading. All rights reserved.
//

import UIKit
import QMUIKit

/// 公告弹窗
class NoticeView: UIView {

    typealias DismissBlock = (UIButton) -> ()
    var dismissBlock : DismissBlock?

    let  logoImg : UIImageView = {
        let img = UIImageView.init();
        
        img.image = ZMImage("notice1");
        return img;
    }()
    
    let  contentView : UIView = {
         let view = UIView.init();
        view.backgroundColor = .white;
         return view;
     }()
    
    
    lazy var titleLabel : QMUILabel = {
        let lab = QMUILabel.init();
        lab.font = UIFont.init(fontType: .medium, fontSize: 20);
        lab.textAlignment = .center;
        lab.textColor = ZMColor.Black.black1;
        lab.numberOfLines = 2;
        return lab;
    }()
    
    lazy var contentLabel : QMUITextView = {
        var lab = QMUITextView.init();
        lab.font = UIFont.init(fontType: .regular, fontSize: 16);
        lab.textColor = ZMColor.Black.black1;
        lab.isEditable = false;
        lab.canPerformPasteActionBlock = { (sender : Any , superValue : Bool)  in
            return false;
        };
        return lab;
    }()
    
    lazy var dismissBtn: UIButton = {
        let btn = UIButton.init();
        btn.setImage(ZMImage("dy_camera_dismiss_btn"), for: .normal);
        btn.addTarget(self, action: #selector(dismissAction(button:)), for: .touchUpInside);
        return btn;
    }()
    
    
    
    //MARK: 🐷 Event Response 🐷
    @objc func dismissAction(button : UIButton)  {
        if self.dismissBlock != nil {
            self.dismissBlock!(button);
        }
    }
    override init(frame: CGRect) {
        super.init(frame: frame);
        
        self.loadDefaultSetting();
        self.initSubViews();
        
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    //    MARK: 🐷 加载默认设置 🐷
    private  func loadDefaultSetting()  {
        self.clipsToBounds = false;
        self.layer.masksToBounds = false;
        self.backgroundColor = .clear;
        
    }
    //    MARK: 🐷 初始化子视图 🐷
    private  func initSubViews()  {
        self.addSubview(self.logoImg);
        self.addSubview(self.contentView);
        self.addSubview(self.dismissBtn);
        self.contentView.addSubview(self.titleLabel);
        self.contentView.addSubview(self.contentLabel);
        
        
        self.layout();
    }
    func layout()  {
        
        ///logo
        self.logoImg.snp.makeConstraints { (make) in
            make.top.centerX.equalToSuperview();
            make.width.height.equalTo(60);
        };
        
        ///内容
        self.contentView.snp.makeConstraints { (make) in
            make.leading.trailing.bottom.equalToSuperview();
            make.top.equalTo(self.logoImg.snp.bottom).offset(10);
        };
        
        
        ///标题
        self.titleLabel.snp.makeConstraints { (make) in
            make.leading.equalToSuperview().offset(20);
            make.trailing.equalToSuperview().offset(-20);
            make.top.equalTo(self.logoImg.snp.bottom).offset(15);
        };
        
        ///内容
        self.contentLabel.snp.makeConstraints { (make) in
            make.leading.trailing.equalTo(self.titleLabel);
            make.top.equalTo(self.titleLabel.snp.bottom).offset(10);
            make.bottom.equalToSuperview().offset(-10);
        };
        
        ///关闭
        self.dismissBtn.snp.makeConstraints { (make) in
            make.top.equalToSuperview().offset(10);
            make.trailing.equalToSuperview().offset(-8);
            make.width.height.equalTo(25);
        };
        
    }
    override func layoutSubviews() {
        super.layoutSubviews();
    }

}
